<?php
namespace App\JsonRpc;
use App\Service\CryptService;
use App\Service\Jwt;
use Hyperf\Di\Annotation\Inject;
use Hyperf\RpcServer\Annotation\RpcService;
/**
 * @RpcService(name="UserService", protocol="jsonrpc-http", server="jsonrpc-http", publishTo="consul")
 */
class UserService implements UserServiceInterface
{
    /**
     * @Inject()
     * @var CryptService
     * */
    protected $crypt;
    public function checkToken(string $token): array
    {
        $result = $this->crypt->decrypt($token);
        if(!$result){
            return ['status' => 'error', 'msg' => '数据错误，请求失败'];
        }
        $result = json_decode($result, true);
        if(!$result || !is_array($result)){
            return ['status' => 'error', 'msg' => '数据错误，数据格式错误'];
        }
        return $result;
    }

    /**
     * @Inject
     * @var Jwt
     * */
    protected $jwt;
    public function getToken(array $params = []):string
    {
        return $this->jwt->getToken($params);
    }

    public function verifySsid(string $token): bool
    {
        return $this->jwt->verify($token) ? true : false;
    }
}